﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace TEmailSpider
{
    class TestCls
    {
        public static double CheckProxyIP(string IP, int port, int timeOut)
        {
            double timeSpan = -1;
            string url = "http://www.baidu.com";
            HttpWebRequest request;
            WebProxy webProxy;
            DateTime begin = DateTime.Now;
            request = (HttpWebRequest)HttpWebRequest.Create(url);
            if (IP != null && IP.Trim().Length > 0)
            {
                webProxy = new WebProxy(IP, port);
            }
            else
            {
                webProxy = new WebProxy();
            }
            try
            {
                request.Timeout = timeOut;
                request.ReadWriteTimeout = timeOut;
                request.ContentType = "text/xml";
                if (IP != null && IP.Trim().Length > 0)
                {
                    request.Proxy = webProxy;
                }
                request.GetResponse();
                DateTime end = DateTime.Now;
                timeSpan = (end - begin).TotalMilliseconds;
            }
            catch { }
            finally
            {
                request.Abort();
            }
            return timeSpan;
        } 
    }
}
